home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_02 / ED-157 / rec_split.c < prev    next >
C/C++ Source or Header  |  1993-09-10  |  2KB  |  74 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22.  
  23. #include "memory.h"
  24. #include "rec.h"
  25. #include "window.h"
  26. #include "ed_dec.h"
  27.  
  28. /******************************************************************************\
  29. |Routine: rec_split
  30. |Callby: insert
  31. |Purpose: Splits a record in two.
  32. |Arguments:
  33. |    prec is the record to be split.
  34. |    byt is the location of the split point. Everything from [byt] forward goes
  35. |            to the new record.
  36. \******************************************************************************/
  37. void rec_split(prec,byt)
  38. rec_ptr *prec;
  39. Int byt;
  40. {
  41.     rec_ptr rec,new;
  42.     Int i;
  43.  
  44.     rec = *prec;
  45.     new = (rec_ptr)imalloc(sizeof(rec_node));
  46.     new->data = (Char *)imalloc(rec->length - byt + 1);
  47.     new->recflags = 1;    /* it is a freeable buffer */
  48.     if((new->length = rec->length - byt) > 0)
  49.         memcpy(new->data,&rec->data[byt],new->length);
  50.     new->data[new->length] = '\0';
  51.     if(rec == BASE)
  52.     {
  53.         insq(new,rec->prev);    /* insert a blank record just before the [eob] */
  54.         *prec = new;    /* we be located at the new record, not [eob] */
  55.     }
  56.     else
  57.     {
  58.         for(i = 0;i < NMARK;i++)
  59.             if(rec == MARKREC[i] && MARKBYT[i] >= byt)
  60.             {
  61.                 MARKREC[i] = new;
  62.                 MARKBYT[i] -= byt;
  63.             }
  64.         if(rec == SELREC && SELBYT > byt)
  65.         {
  66.             SELREC = new;
  67.             SELBYT -= byt;
  68.         }
  69.         rec_trim(prec,byt,rec->length);    /* trim what follows byt in original rec */
  70.         insq(new,*prec);
  71.     }
  72. }
  73.  
  74.